package com.example.foo.admin.web.fttcard20220715;

import java.util.List;

import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestParam;

import com.ruoyi.common.core.domain.AjaxResult;
import com.example.core.PageResult;
import com.example.core.Pageable;
import com.example.foo.fttcard20220715.model.FttCard20220715;
import com.example.foo.fttcard20220715.query.FttCard20220715Query;
import com.example.foo.fttcard20220715.service.FttCard20220715Service;

@Deprecated//TODO remove
@org.springframework.web.bind.annotation.RestController
public class FttCard20220715Action {

	private final FttCard20220715Service fttCard20220715Service;

	public FttCard20220715Action(FttCard20220715Service fttCard20220715Service) {
		this.fttCard20220715Service = fttCard20220715Service;
	}

	@GetMapping("/api/fttcard20220715s")
	public AjaxResult index(FttCard20220715Query fttCard20220715Query, Pageable pageable) {
		PageResult<FttCard20220715> pageResult = fttCard20220715Service.findFttCard20220715s(fttCard20220715Query, pageable);
		return AjaxResult.successData(pageResult);
	}

	@PostMapping("/api/fttcard20220715s/batch")
	public AjaxResult createFttCard20220715Batch(@RequestParam("cellphones") List<String> cellphones) {
		if (cellphones == null || cellphones.isEmpty()) {
			return AjaxResult.error(400, "cellphones must not be null");
		}

		for (String cellphone : cellphones) {
			fttCard20220715Service.createFttCard20220715(cellphone);
		}

		return AjaxResult.success();
	}

	@PutMapping("/api/fttcard20220715s/{id}/stateBatch")
	public AjaxResult updateFttCard20220715StateBatch(@RequestParam("ids") List<Long> ids, FttCard20220715.State state) {
		if (ids == null || ids.isEmpty()) {
			return AjaxResult.error(400, "ids must not be null");
		}
		if (state == null) {
			return AjaxResult.error(400, "state must not be null");
		}

		for (Long id : ids) {
			fttCard20220715Service.updateFttCard20220715(id, state);
		}

		return AjaxResult.success();
	}

}
